//获取应用实例
const app = getApp();
// 引入AES.js
var baseJs = require("../../common/base.js");
Page({

  /**
   * 页面的初始数据
   */
  data: {
    listData: [],
    // 
    uid:"",
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    this.setData({
      uid: wx.getStorageSync('uid'),
    })
    this.GetMyConsumerCoupon();
  },

  
  GetMyConsumerCoupon: function() {
    var that = this;
    var uid = this.data.uid;
    var listData = this.data.listData;
    wx.request({
      url: baseJs.api + baseJs.encryUrl("method=GetMyConsumerCoupon&UID=" + uid),
      success: function(res) {
        listData = JSON.parse(baseJs.decryUrl(res.data)).ResultData;
        for (var i = 0; i < listData.length; i++) {
          listData[i].UseTime = listData[i].UseTime.split('T')[0].replace(/-/g, '.');
        }
        that.setData({
          listData: listData,
        })
        console.log(listData);
      }
    })
  },
  //删除优惠券
  delTicket: function(e) {
    var that = this;
    var ticketId = e.currentTarget.dataset.ticketid;
    var index = e.currentTarget.dataset.index;
    wx.showModal({
      content: '是否删除该优惠券？',
      confirmText: "确定",
      cancelText: "取消",
      success: function(res) {
        if (res.confirm) {
          // 点击确定
          wx.request({
            url: baseJs.api + baseJs.encryUrl("method=DeleteGift&GiftId=" + ticketId),
            success: function(res) {
              var json = JSON.parse(baseJs.decryUrl(res.data));
              wx.showToast({
                title: json.ResultMsg,
                icon: 'none',
                duration: 2000
              });
              that.GetMyConsumerCoupon();
            },
          })
        } else {
          // 点击取消
        }
      },
    });


  },
  // 
})